//
//  JLMainTabBarController.m
//  LIangeNews
//
//  Created by sun on 16/1/10.
//  Copyright © 2016年 sun. All rights reserved.
//

#import "JLMainTabBarController.h"
#import "JLNavigationController.h"
#import "JLButtomTabBar.h"
@interface JLMainTabBarController ()<JLButtomTabBarDelegate>
@property(nonatomic,strong)NSArray * tabBarName;
@end

@implementation JLMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupChildViewControllers];
    
    [self setupCustomTabBar];
    
}
- (NSArray *)tabBarName
{
    if (_tabBarName == nil) {
        _tabBarName = @[@"新闻", @"阅读", @"视听", @"发现", @"我"];
    }
    return _tabBarName;
}
-(void)setupChildViewControllers{
    JLNavigationController * navMainHall = [self navigationControllerWithStoryboardName:@"Main"];
    JLNavigationController * navReadingHall = [self navigationControllerWithStoryboardName:@"Reading"];
    JLNavigationController * navVideoHall = [self navigationControllerWithStoryboardName:@"Video"];
    JLNavigationController * navDiscoverHall = [self navigationControllerWithStoryboardName:@"Discover"];
    JLNavigationController * navMeHall = [self navigationControllerWithStoryboardName:@"Me"];


    self.viewControllers = @[navMainHall, navReadingHall,navVideoHall,navDiscoverHall,navMeHall];
    
}
-(JLNavigationController *)navigationControllerWithStoryboardName:(NSString *)name{
    
    UIStoryboard * storyboard = [UIStoryboard storyboardWithName:name bundle:nil];
    
    return [storyboard instantiateInitialViewController];
}
-(void)setupCustomTabBar{
    JLButtomTabBar * tabBar = [[JLButtomTabBar alloc]init];
    NSUInteger  count = self.viewControllers.count;
    for (int i = 0; i < count ; i++) {
        [tabBar addButtomTabBarButtonWithNorImage:[NSString stringWithFormat:@"TabBar%d",i+1] seleImage:[NSString stringWithFormat:@"TabBar%dSel",i+1]title:self.tabBarName[i]];
         
        tabBar.delegate = self;
        tabBar.frame = self.tabBar.bounds;
        [self.tabBar addSubview:tabBar];
    }
    
    
}
- (void)buttomTabBar:(JLButtomTabBar *)ButtonTabBar didClickButtomTabBarWithIndex:(int)index{
    self.selectedIndex = index;
}

@end
